/**
 * 
 */
package lottery;

import java.text.DecimalFormat;
import java.util.Scanner;

/**
 * @author blank
 *
 */
public class lotteryOs {
	static int index =1;
	static int first =0;
	static int second =0;
	static int third =0;
	//让两个int类型的数据相除并输出保留两位小数
	DecimalFormat decimalFormat =null;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 用户选择
		int choose = -1;

		System.out.println("----欢迎登录抽奖系统！----");
		while (true) {
			System.out.println("1.开始抽奖   2.退出");
			choose = sc.nextInt();
			if (choose == 1) {
				// 进入抽奖
				enterLottery();
			} else if (choose == 2) {
				float one=(float)first*100/index;
				float two=(float)second*100/index;
				float three=(float)third*100/index;
				DecimalFormat df = new DecimalFormat("0.00");
				String ones =df.format(one);
				String twos =df.format(two);
				String threes =df.format(three);
				System.out.println("一共有"+index+"名用户参加了抽奖，"+"一等奖占了"+ones+"%"+"，二等奖占了"+twos+"%"+"，三等奖占了"+threes+"%");
				System.out.println("谢谢使用！");
				break;
			} else {
				System.out.println("输入错误，请重试！");
			}

		}

	}

	/**
	 * 
	 */
	private static void enterLottery() {
		// TODO Auto-generated method stub
		int randomNum = (int) (Math.random() * 100);
		//测试
		//System.out.println(randomNum);
		System.out.println("您是第"+index+"名用户，抽中的数字是"+randomNum);
		if (randomNum>=95) {
			System.out.println("恭喜你，中了特等奖");
		}else if (randomNum<95&&randomNum>=85) {
			System.out.println("恭喜你，中了一等奖");
			first++;
		}else if (randomNum<85&&randomNum>=75) {
			System.out.println("恭喜你，中了二等奖");
			second++;
		} else if (randomNum<75&&randomNum>=60) {
			System.out.println("恭喜你，中了三等奖");
			third++;
		}  
		else {
			System.out.println("谢谢惠顾，下次一定！");
		}
		index++;
		
	}

}
